﻿/* Author:
 *  Andrea Russino
 */ 

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace TripLOAMobile
{
    /// <summary>
    /// This class provides the access to some WindowsAPIs.
    /// </summary>
    class WinAPI
    {
        public const UInt32 SHDB_SHOW = 0x0001; 
        public const UInt32 SHDB_HIDE = 0x0002; 
        public const int GWL_STYLE = -16; 
        public const UInt32 WS_NONAVDONEBUTTON = 0x00010000;

        /// <summary>
        /// Controls the showing of the done button for dialogs.
        /// </summary>
        /// <param name="hWnd">The handle to the window that owns the button.</param>
        /// <param name="show">If set to <c>true</c> [show].</param>
        public static void ShowDoneButton(IntPtr hWnd, bool show)
        {
            SHDoneButton(hWnd, show ? SHDB_SHOW : SHDB_HIDE);
        }

        /// <summary>
        /// This function is provided for applications that need to dynamically show or 
        /// hide the OK button based on some state that the application is in.
        /// </summary>
        /// <param name="hWnd">The top-level window handle requesting the Done button.</param>
        /// <param name="dwState">This parameter will contain one of the following states.
        /// <list type="bullet">
        /// <item>
        /// <term>SHDB_SHOW</term>
        /// <description>Adds the WS_EX_CAPTIONOKBTN to hwndRequester. 
        /// Next time this window becomes the foreground window, the Done button will appear. 
        /// Note that hwndRequester must NOT have the WS_CAPTION style set.</description></item>
        /// <item>
        /// <term>SHDB_HIDE</term>
        /// <description>Removes the WS_EX_CAPTIONOKBTN from hwndRequester. 
        /// Next time this window becomes the foreground window, the Done button will not appear.</param>
        /// </description>
        /// </item>
        /// </list>
        /// <returns><i>True</i> indicates success. <i>False</i> indicates failure.</returns>
        [DllImport("aygshell.dll")]
        private static extern bool SHDoneButton(IntPtr hWnd, UInt32 dwState);

        /// <summary>
        /// The SetFocus function sets the keyboard focus to the specified window. 
        /// The window must be attached to the calling thread's message queue. 
        /// </summary>
        /// <param name="hWnd">[in] Handle to the window that will receive the keyboard input. 
        /// If this parameter is NULL, keystrokes are ignored.</param>
        /// <returns>If the function succeeds, the return value is the handle to the window 
        /// that previously had the keyboard focus. If the hWnd parameter is invalid or the 
        /// window is not attached to the calling thread's message queue, the return value is NULL.</returns>
        [DllImport("coredll")]
        public static extern IntPtr SetFocus(IntPtr hWnd);

        /*public static void HideXButton(IntPtr hWnd) {
            UInt32 dwStyle = GetWindowLong(hWnd, GWL_STYLE);
            if ((dwStyle & WS_NONAVDONEBUTTON) == 0)
                SetWindowLong(hWnd, GWL_STYLE, dwStyle | WS_NONAVDONEBUTTON);
        }

        [DllImport("coredll.dll")]
        public static extern UInt32 SetWindowLong( IntPtr hWnd, int nIndex, UInt32 dwNewLong); 
        
        [DllImport("coredll.dll")]
        public static extern UInt32 GetWindowLong( IntPtr hWnd, int nIndex);*/
    }
}
